package com.run2code.design.behavioral.iterator;

import com.run2code.design.behavioral.iterator.base.Iterator;

import java.util.List;

/**
 * 组织迭代器类
 * 实现Iterator类，用于遍历组织结构中的员工。
 * 关注公众号【奔跑的码畜】，一起进步不迷路
 *
 * @author 第七人格
 * @date 2024/01/30
 */
public class OrganizationIterator implements Iterator<Employee> {
    private List<Employee> employees;
    private int currentIndex;

    public OrganizationIterator(List<Employee> employees) {
        this.employees = employees;
        currentIndex = 0;
    }

    @Override
    public boolean hasNext() {
        return currentIndex < employees.size();
    }

    @Override
    public Employee next() {
        return employees.get(currentIndex++);
    }
}
